//
//  UNIVoiceBottomView.m
//  CAShapeLayerVoiceView
//
//  Created by 宇宙执政 on 16/11/4.
//  Copyright © 2016年 yujianbinMAC. All rights reserved.
//

#import "UNIVoiceBottomView.h"
#import "UIView+UNIViewExtension.h"

@interface UNIVoiceBottomView()


/**
 中间view
 */
@property (nonatomic, strong)UIView *cenLineView;


/**
 中间线layer
 */
@property (nonatomic, strong)CAShapeLayer *cenLineLayer;


/**
 底部view
 */
@property (nonatomic, strong)UIView *bomLineView;

/**
 底部线layer
 */
@property (nonatomic, strong)CAShapeLayer *bomLineLayer;


/**
 线宽
 */
@property (nonatomic, assign)CGFloat lineWith;


@property (nonatomic, strong)UIColor *lineColor;
@end

@implementation UNIVoiceBottomView

- (instancetype)initWithFrame:(CGRect)frame lineWith:(CGFloat)lineWith lineColor:(UIColor *)lColor{
    if (self = [super initWithFrame:frame]) {
        _lineWith = lineWith;
        _lineColor = lColor;
     
        [self setup];
    }
    
    return self;
}

-(void)setup{
    
    //
    _cenLineView = [[UIView alloc] initWithFrame:CGRectMake((self.width-_lineWith)/2, 0, _lineWith, self.height*0.6)];
    _cenLineLayer = [self drawOutSideLine:_cenLineView.bounds color:_lineColor];
    [_cenLineView.layer addSublayer:_cenLineLayer];
    [self addSubview:_cenLineView];
    
    //
    _bomLineView = [[UIView alloc] initWithFrame:CGRectMake((self.width-self.width*0.4)/2, self.height*0.6, self.width*0.4, _lineWith)];
    _bomLineView.backgroundColor = [UIColor redColor];
    _bomLineLayer = [self drawOutSideLine:_bomLineView.bounds color:_lineColor];
    [_bomLineView.layer addSublayer: _bomLineLayer];
    
    [self addSubview:_bomLineView];
}

-(CAShapeLayer *)drawOutSideLine:(CGRect)frame color:(UIColor *)color{
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.fillColor = color.CGColor;
    layer.lineWidth = _lineWith;
    layer.frame = frame;
    layer.lineCap = kCALineJoinRound;
    
    layer.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, frame.size.width, frame.size.height) cornerRadius:self.width*0.4].CGPath;
    
    return layer;
}




@end
